package com.tencent.supersonic;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexExample {
    public static void main(String[] args) {
        String date = "SELECT 用户 FROM 超音数产品 WHERE 数据日期 >= '2023-08-01' AND 数据日期 <= '2023-08-31' ORDER BY 访问次数";
        String dateRegex = "'\\d{4}-\\d{2}-\\d{2}'";
        String dateTimeRegex = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}";
 
        Pattern datePattern = Pattern.compile(dateRegex);
        Pattern dateTimePattern = Pattern.compile(dateTimeRegex);
 
        Matcher dateMatcher = datePattern.matcher(date);
        Matcher dateTimeMatcher = dateTimePattern.matcher(date);
        while (dateMatcher.find()) {
        	String temp = dateMatcher.group();
        	System.out.println(temp);
        	
        }

 
        if (dateMatcher.matches()) {
        	String s = dateMatcher.group();
        	System.out.println(s);
            System.out.println("This is a valid SQL date.");
        }
 
        if (dateTimeMatcher.matches()) {
            System.out.println("This is a valid SQL date and time.");
        }
    }
}